package com.mdlib.helper.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ljlib.help.R;
import com.mdlib.helper.model.AccountModel;
import com.mdlib.helper.ui.UIHelper;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：HQY on 17/2/8 15:09
 * 邮箱：hqy_xz@126.com
 */

public class OutLoginDialogFragment extends DialogFragment {

    @Bind(R.id.tv_login_out)
    TextView mTvLoginOut;

    public static OutLoginDialogFragment newInstance() {
        return new OutLoginDialogFragment();
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Dialog_Share);
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_out, null);
        builder.setView(view);
        ButterKnife.bind(this, view);
        return builder.create();
    }


    @Override
    public void onStart() {
        super.onStart();

        // 设置宽度为屏宽、靠近屏幕底部。
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams wlp = window.getAttributes();
        wlp.gravity = Gravity.CENTER;
        wlp.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(wlp);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @OnClick(R.id.tv_login_out)
    public void onClick() {
        AccountModel.getInstance().clearCache();
        UIHelper.showLogin(getActivity());
    }
}
